package com.frx.leetcode.classify.array;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * Created with IDEA
 *
 * @author: xrf
 * @Date: 2019/11/6
 * @Time: 16:00
 */
public class Intersection {
    public static void main(String[] args){
        int[] arr1 = {1,2,3,2,1};
        int[] arr2 = {3,2};
    }
    public static void select(int[] arr1,int[] arr2){
        TreeMap<Integer,Integer> map = new TreeMap();
        for (int i=0;i<arr1.length;i++){
            if (map.containsKey(arr1[i])){
                map.put(arr1[i],map.get(arr1[i]) + 1);
            } else {
                map.put(arr1[i],1);
            }
        }
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<arr2.length;i++){
            if (map.containsKey(arr2[i]) && map.get(arr2[i]) != 0){
                list.add(arr2[i]);
                map.put(arr2[i],map.get(arr2[i]) - 1);
            }
        }
        int[] nums = new int[list.size()];
        for (int i=0;i<list.size();i++){
            nums[i] = list.get(i);
        }



    }


}
